package org.zhouhe.web.util;
 
import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections.MapUtils;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;

public class FtlUtils {
	public static void main(String[] args) {
		try {
//			FreeMarkerTemplateUtils.processTemplateIntoString(template, model)
			
			Configuration cfg = new Configuration();
			cfg.setDirectoryForTemplateLoading(new File("WebContent/common/template/tag/"));
			cfg.setObjectWrapper(new DefaultObjectWrapper());
			long s = System.currentTimeMillis();
			for(int i=0; i<10000; i++){
				Template ftl = cfg.getTemplate("tag_scripts.ftl");
			}
			System.out.println(System.currentTimeMillis() - s);
			Map<String, Object> root = new HashMap<String, Object>();
			root.put("functionName", "selectAll");
//			ftl.process(root, new OutputStreamWriter(System.out));
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
class MapBuilder{
    public static <V, V1 extends V, V2 extends V, V3 extends V> Map<String, V> toMap(String name1, V1 value1, String name2, V2 value2, String name3, V3 value3) {
    	return populateMap(new HashMap<String, V>(), name1, value1, name2, value2, name3, value3);
    }
    
    @SuppressWarnings("unchecked")
    private static <K, V> Map<String, V> populateMap(Map<String, V> map, Object... data) {
        for (int i = 0; i < data.length;) {
            map.put((String) data[i++], (V) data[i++]);
        }
        return map;
    }
	
	public static void main(String[] args) {
		Map<String, Object> map = MapBuilder.toMap("asdf", 2L, "b", 3F, "c", "CCC");
		System.out.println(map);
	}
}
class MapMisc extends MapUtils{
	
}
